package com.example.springstudyvue.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: linKe
 * @Date: 2021/11/24 16:18
 * @FileName: MyMetaObjectHandler
 * @version: 1.0
 * @Description: 新增和添加时更新时间的策略
 */
@Component
@Log4j2
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 插入式的填充策略
     * @param metaObject    元对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    /**
     * 更新时的策略
     * @param metaObject   元对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime",new Date(),metaObject);

    }
}

